<template>
    <div>
        <dv-digital-flop :config="config" style="width:200px;height:50px;" v-if="typeform=='hasgoods'"/>
        <dv-digital-flop :config="config" style="width:200px;height:50px;" v-if="typeform=='haskinds'"/>
        <dv-digital-flop :config="config" style="width:200px;height:50px;" v-if="typeform=='hastotalprices'"/>
    </div>
</template>

<script>
    //翻牌器

    function formatter(number) {
        const numbers = number.toString().split('').reverse()
        const segs = []
        while (numbers.length) segs.push(numbers.splice(0, 3).join(''))
        return segs.join('').split('').reverse().join('')
    }

    export default {
        route: false,
        props: {typeform: {type: String}},
        data() {
            return {
                config: {
                    number: [999],
                    content: '{nt}个',
                    formatter
                }
            }
        },
        mounted() {
            const form = this.$store.state.kinds;
            //根据type传递的值判断获取什么内容
            switch (this.typeform) {
                //所有商品总和
                case 'hasgoods':
                    this.config.number[0] = form.reduce(function (acc, cur) {
                        return acc + cur.hasgoods
                    }, 0)
                    this.config = {...this.config}
                    break;
                case 'haskinds':
                    //所有类别
                    this.config.number[0] = form.length
                    this.config = {...this.config}
                    break;
                case 'hastotalprices':
                    //所有商品价格之和
                    this.config.number[0] = form.reduce((acc, cur) => acc + cur.totalprices, 0)
                    this.config.toFixed = 2,
                    this.config.content = '{nt}元',
                    this.config = {...this.config}
                    break;
                default:
                    console.log('houdunwang.com')
            }
        }
    }
</script>

<style scoped>

</style>